package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.ApAuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * APP文章作者信息表 前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/author")
public class ApAuthorController {

    @Autowired
    private ApAuthorService apAuthorService;

    /**
     * 根据userId查询作者信息
     *
     * @param id
     * @return
     */
    @GetMapping("/findByUserId/{id}")
    public ApAuthor findByUserId(@PathVariable("id") Integer id) {
        return apAuthorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId, id));
    }

    /**
     * 保存作者信息
     *
     * @param apAuthor
     * @return
     */
    @PostMapping("/save")
    public boolean save(@RequestBody ApAuthor apAuthor) {
        return apAuthorService.save(apAuthor);
    }

}
